package io.geekidea.boot.system.query;

import io.geekidea.boot.framework.page.BasePageQuery;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.io.Serial;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 系统用户查询参数
 *
 * @author geekidea
 * @since 2022-12-26
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema(description = "系统用户查询参数")
public class SysUserQuery extends BasePageQuery {
    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "用户名")
    private String username;

    @Schema(description = "角色ID")
    private List<Long> roleIds;

    @Schema(description = "手机号码")
    private String phone;

    @Schema(description = "状态，0：禁用，1：启用")
    private Boolean status;

    @Schema(description = "创建开始时间")
    private Date startCreateTime;

    @Schema(description = "创建结束时间")
    private Date endCreateTime;

    @Schema(description = "机构集合ID")
    private List<Long> orgIds;

    @Schema(description = "机构ID")
    private Long orgId;

    public void setRoleIds(String roleIds) {
        if (StringUtils.isNotEmpty(roleIds)) {
            this.roleIds = Arrays.stream(roleIds.split(",")).map(Long::parseLong).collect(Collectors.toList());
        } else {
            this.roleIds = null;
        }
    }

    public void setOrgIds(String orgIds) {
        if (StringUtils.isNotEmpty(orgIds)) {
            this.orgIds = Arrays.stream(orgIds.split(",")).map(Long::parseLong).collect(Collectors.toList());
        } else {
            this.orgIds = null;
        }
    }
}

